package datastructure.queue;

import datastructure.heap.MaxHeap;

public class PriorityQueue<E extends Comparable<E>> implements Queue<E> {

    private MaxHeap<E> maxHeap;

    public PriorityQueue() {
        maxHeap = new MaxHeap<>();
    }

    @Override
    public void enqueue(E e) {
        maxHeap.add(e);

    }

    @Override
    public E dequeue() {
        // 这里需要判断对是否为空,但是在extractMax中已经判断过了
        return maxHeap.extractMax();

    }

    @Override
    public E peek() {
        // 判断堆是否为空,在peekMaxHeap中进行了判断
        return maxHeap.peekMaxHeap();
    }

    @Override
    public int getSize() {
        // TODO Auto-generated method stub
        return maxHeap.getSize();
    }

    @Override
    public boolean isEmpty() {
        // TODO Auto-generated method stub
        return maxHeap.isEmpty();
    }

}
